/** 
 * @(#)Resource.java 1.0.0 2015年11月4日 下午4:34:09  
 *  
 * Copyright © 2015 善林金融.  All rights reserved.  
 */ 

package com.service;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.entity.ResourcesEntity;
import com.entity.ResourcesSignRecordEntity;
import com.repository.ResourcesRepository;
import com.repository.ResourcesSignRecordRepository;

/**   
 * 
 *  
 * @author  HuYaHui
 * @version $Revision:1.0.0, $Date: 2015年11月4日 下午4:34:09 $ 
 */
@Service
public class ResourceService {

	@Autowired
	private ResourcesRepository resourcesRepository;

	@Autowired
	private ResourcesSignRecordRepository resourcesSignRecordRepository;

	

	//申请列表
	public List<Map<String,Object>> signlist(){
		List<Map<String,Object>> list=resourcesSignRecordRepository.findByCondition();
		return list;
	}
	
	//申请人
	@Transactional(readOnly=false)
	public void saveRecord(ResourcesSignRecordEntity entity){
		entity.setSignStatus("申请中");
		entity.setCreateDate(new Date());
		resourcesSignRecordRepository.save(entity);
	}
	@Transactional(readOnly=false)
	public void update(String rejectReason,String signStatus,String id,String holder){
		ResourcesSignRecordEntity rsr=resourcesSignRecordRepository.findOne(id);
		rsr.setRejectReason(rejectReason);
		rsr.setSignStatus(signStatus);
		rsr.getResourcesEntity().setHolder(holder);
		resourcesSignRecordRepository.save(rsr);
	}
	
	//信息列表
	public List<ResourcesEntity> resourceList(String... properties){
		//
		return resourcesRepository.findAll(new Sort(Direction.DESC,properties));
	}
	
	//添加资源信息
	@Transactional(readOnly=false)
	public void saveResource(ResourcesEntity entity){
		entity.setHolder("仓库");
		entity.setCreateDate(new Date());
		resourcesRepository.save(entity);
	}
}
